import 'package:flutter/material.dart';
import 'package:sleep_manager/ui/widget/custom_app_bar.dart';

import '../../utils/navigation_utils.dart';
import '../widget/setting/setting_item_widget.dart';

/// 设置页面
class SettingPage extends StatefulWidget {

  const SettingPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return _SettingPageState();
  }

}

class _SettingPageState extends State<SettingPage> {

  // 页面跳转
  final NavigationUtils navigationUtils = NavigationUtils();

  // 阴影 - 定义常量减少重复代码
  final boxShadow = BoxShadow(
      color: Colors.black.withOpacity(0.1),
      blurRadius: 8,
      spreadRadius: 2,
      offset: const Offset(4, 4));

  // 分割线
  final divider = Container(
    height: 1,
    color: const Color(0xFFEAEAEA),
    margin: const EdgeInsets.symmetric(vertical: 16),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const CustomAppBar(title: "设置"),
      backgroundColor: const Color(0xFFF7F7F7),
      body: Container(
        alignment: Alignment.topLeft,
        padding: const EdgeInsets.fromLTRB(16, 10, 16, 20),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.fromLTRB(20, 22, 32, 22),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12),
                    boxShadow: [boxShadow]),
                child: SettingItemWidget(
                    title: '我的家人',
                    iconPath: 'assets/images/my_family.svg',
                    onTap: () =>
                        navigationUtils.navigateToPage(context, 'Family')),
              ),
              Container(
                margin: const EdgeInsets.only(top: 15),
                padding: const EdgeInsets.fromLTRB(16, 32, 32, 32),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(15),
                    boxShadow: [boxShadow]),
                child: Column(
                  children: [
                    SettingItemWidget(
                        title: '我的设备',
                        iconPath: 'assets/images/my_devices.svg',
                        onTap: () =>
                            navigationUtils.navigateToPage(context, 'Devices')),
                    divider,
                    SettingItemWidget(
                        title: '监测设置',
                        iconPath: 'assets/images/monitor_setting.svg',
                        onTap: () =>
                            navigationUtils.navigateToPage(context, 'MonitorSetting')),
                    divider,
                    SettingItemWidget(
                        title: '系统设置',
                        iconPath: 'assets/images/system_setting.svg',
                        onTap: () =>
                            navigationUtils.navigateToPage(context, 'SystemSetting')),
                    divider,
                    SettingItemWidget(
                        title: '关于',
                        iconPath: 'assets/images/about.svg',
                        onTap: () =>
                            navigationUtils.navigateToPage(context, 'About')),
                    divider
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

}
